package org.bpms.controller.admin;

import java.util.HashMap;
import java.util.Map;

import org.bpms.interceptor.WebInterceptor;
import org.bpms.model.admin.Member;
import org.bpms.service.admin.MemberService;

import com.jfinal.aop.Clear;
import com.jfinal.aop.Enhancer;
import com.jfinal.core.Controller;

/**
 * 会员控制器
 * @author hupei
 *
 */
public class MemberController extends Controller{
	private MemberService memberService = Enhancer.enhance(MemberService.class);
	
	/**
	 * 后台会员列表
	 */
	@Clear(WebInterceptor.class)
	public void index(){
		Map<String,Object> pagemap = new HashMap<String, Object>();
		String tabid = getPara("tabid");
		String stime = getPara("stime", "");
		String etime = getPara("etime", "");
		String nickname = getPara("nickname", "");
		Integer pageNumber = getParaToInt("pageCurrent", 1);//要访问第几页，默认1
		Integer pageSize = getParaToInt("pageSize", 30);//每页多少条数据，默认15
		String orderField = getPara("orderField", "ctime");//对什么字段排序，默认空字符串
		String orderDirection = getPara("orderDirection", "desc");//升序还是降序，默认升序
		memberService.findAll(nickname, stime, etime, pageNumber, 
				            pageSize, orderField, orderDirection, pagemap);
		setAttr("page",pagemap);
		setAttr("tabid", tabid);
		render("/admin/member/member.html");
	}
	
	/**
	 * 提供给外部的接口
	 */
	@Clear
	public void member(){
		String openid = getPara("openid" , "");
		Member member = memberService.findById(openid);
		renderJson(member);
	}
}
